﻿Imports System.Data.SqlClient

Public Class clsSM
    Private mintidSM As Integer
    Private mstrZona As String
    Private mdblMonto As Double
    Public Property IdSM() As Integer
        Get
            Return mintidSM
        End Get
        Set(ByVal value As Integer)
            mintidSM = value
        End Set
    End Property
    Public Property Zona() As String
        Get
            Return mstrZona
        End Get
        Set(ByVal value As String)
            mstrZona = value
        End Set
    End Property
    Public Property Monto() As Double
        Get
            Return mdblMonto
        End Get
        Set(ByVal value As Double)
            mdblMonto = value
        End Set
    End Property
    Public Sub New()
        mintidSM = 0
        mdblMonto = 0
        mstrZona = ""
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into SalariosMinimos (" & _
                            "IdSM," & _
                            "Zona," & _
                            "Monto)" & _
                            "VALUES (" & _
                            "@IdSM," & _
                            "@Zona," & _
                            "@Monto)"



        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdSM", mintidSM)
        Command.Parameters.AddWithValue("Zona", mstrZona)
        Command.Parameters.AddWithValue("Monto", mdblMonto)

        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Public Sub Actualizar()
        Dim sql As String = "UPDATE  SalariosMinimos SET " & _
                            "Monto=@Monto " & _
                            "WHERE IdSM=@IdSM"



        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdSM", mintidSM)
        Command.Parameters.AddWithValue("Zona", mstrZona)
        Command.Parameters.AddWithValue("Monto", mdblMonto)

        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el registro ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If

    End Sub
End Class
